import { async } from '@angular/core/testing';
import { Component,Injectable, OnInit,OnChanges, ViewChildren } from '@angular/core';
import { ActivatedRoute,Router } from '@angular/router';

import { NavController,ModalController } from '@ionic/angular';
import { VstudentinfoService } from '../provider/vstudentinfo.service';
import { QueryModelWindowComponent } from './query-model-window/query-model-window.component';

@Component({
  selector: 'app-vstudy-info',
  templateUrl: 'vstudy-info.html',
  styleUrls: ['vstudy-info.scss'],
})
@Injectable({
  providedIn: 'root'
})

export class VstudyInfoComponent implements OnInit {

  //@ViewChildren(QueryModelWindowComponent)
  //queryModelWindowComponent: QueryModelWindowComponent;
  fileUrl = "http://10.84.111.205:21021/browse/UploadFile//aaa//";
  classFlag = false;
  item :number;

  vstudylist: any[];
  isShowQueryCondition = false;
  constructor(public navController: NavController, public vstudentService: VstudentinfoService,
    public modalController: ModalController,public activatedRoute: ActivatedRoute,public router: Router) {


  }

  ngOnInit() {
    //this.item = this.activatedRoute.snapshot.params['item'];
   
    this.getVstudyList();
    
    //this.vstudylist = this.getVstudyList();
  }

  goback(): void {
    this.navController.back();
    //this['navController'].navigateBack('tabs');
    //this.navController.navigateRoot(['/tabs']).then(()=>{location.reload();});
    //this.navController.navigateBack(['/tabs/tab1']);
    //location.reload();
    //this.router.navigate(['']);
    //this.router.navigateByUrl('', { replaceUrl: true });
  }

  async getVstudyList() {

    (await this.vstudentService.getVStudyList()).subscribe((response: any) => this.vstudylist = response.body.result);

  }
  async getVstudyListByAttId() {

    (await (this.vstudentService.getVStudyListByTypeId(this.item))).subscribe((response: any) => this.vstudylist = response.body.result);

  }

  async onQueryClick() {
    let modal;
    if (!this.classFlag) {
      modal = await this.modalController.create({
        component: QueryModelWindowComponent,
        mode: "md",
        showBackdrop: true,
        componentProps: {},
        cssClass: "modalWindow"
      });
      modal.present();
      this.classFlag = true;

      await modal.onDidDismiss().then(async (res: any) => {
        
        if(res.data!=undefined&&res.data!=null)
        {
          this.item=res.data.item;
         this.getVstudyListByAttId();
        }
        else
        {
          this.getVstudyList();
        }

        this.classFlag = false;
      });

    }
    else {
      //模态框被关闭后回回调该方法 res 为返回值
      modal = await this.modalController.dismiss();

    }

  }

  async onVoted(item: number) {
    (await this.vstudentService.getVStudyListByTypeId(item)).subscribe((response: any) => this.vstudylist = response.body.result);

  }



}



